<?php

$di = \application\units\Di::getInstance();

['where' => $where, 'bindValue' => $bindValue, 'limit' => $limit, 'order' => $order] = $di->businessCommonQuery->build();

$params = [
    'admin_id'  => $di->auth->id,
    'only_auth' => $di->request->params('only_auth', 0),
];

if ($params['admin_id']) {
    if ($params['only_auth'] == 0) {
        $adminIds = $di->auth->getChildrenRoleAdminIds($params['admin_id'], true);
    } else {
        $adminIds = [$params['admin_id']];
    }
    $where                  .= ' and admin_id in (:admin_ids)';
    $bindValue['admin_ids'] = $adminIds;
}

$total = $di->db->find(sprintf('select count(*) total from admin_operation_log where 1=1 %s', $where), $bindValue)['total'];
$rows  = $di->db->query(sprintf('select * from admin_operation_log where 1=1 %s %s %s', $where, $order, $limit), $bindValue);

return [
    'total' => $total,
    'rows'  => $rows,
];
